package com.ttxs.uaa.api.remote;

import com.ttxs.common.core.vo.R;
import com.ttxs.common.core.vo.Token;
import com.ttxs.common.core.vo.RemoteLoginVO;
import com.ttxs.uaa.service.IRemoteUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import static com.ttxs.common.core.constant.Api.REMOTE_LOGIN;

@RestController
@RequiredArgsConstructor
@Slf4j
public class RemoteLoginApi {
    private final IRemoteUserService remoteUserService;

    @PostMapping(REMOTE_LOGIN)
    public R<Token> login(@RequestBody RemoteLoginVO remoteLoginVO) {
        try {
            Token token = remoteUserService.remoteLogin(remoteLoginVO);
            return R.ok(token);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(e.getMessage());
        }
    }

}
